package com.tao.admin.service.impl;

import com.tao.admin.service.CategoryService;
import com.tao.clients.CategoryClient;
import com.tao.param.PageParam;
import com.tao.pojo.Category;
import com.tao.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 86130
 * 类别业务实现
 */
@Service
@Slf4j
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private CategoryClient categoryClient;

    /**
     * 分页查询方法
     *
     * @param pageParam
     * @return
     */
    @Cacheable(value = "list.category",key = "#pageParam.currentPage+'-'+#pageParam.pageSize")
    @Override
    public R pageList(PageParam pageParam) {
        R r = categoryClient.adminPageList(pageParam);
        log.info("CategoryServiceImpl.pageList业务结束,结果：{}",r);
        return r;
    }

    /**
     * 进行分类数据添加
     *
     * @param category
     * @return
     */
    @CacheEvict(value = "list.category", allEntries = true)
    @Override
    public R adminSave(Category category) {
        R r = categoryClient.adminSave(category);
        log.info("CategoryServiceImpl.adminSave业务结束,结果：{}",r);
        return r;
    }

    /**
     * 类别删除
     *
     * @param categoryId
     * @return
     */
    @CacheEvict(value = "list.category", allEntries = true)
    @Override
    public R adminRemove(Integer categoryId) {
        R r = categoryClient.adminRemove(categoryId);
        log.info("CategoryServiceImpl.adminRemove业务结束,结果：{}",r);
        return r;
    }

    /**
     * 修改类别信息
     *
     * @param category
     * @return
     */
    @CacheEvict(value = "list.category", allEntries = true)
    @Override
    public R adminUpdate(Category category) {
        R r = categoryClient.adminUpdate(category);
        log.info("CategoryServiceImpl.adminUpdate业务结束,结果：{}",r);
        return r;
    }
}
